package models

import (
	"gorm.io/gorm"
	"time"
)

// Order 主订单表
type Order struct {
	ID               uint64         `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
	OrderNo          string         `gorm:"type:varchar(32);uniqueIndex;not null;comment:订单号" json:"order_no"`
	OrderType        int8           `gorm:"type:tinyint;not null;comment:订单类型(1-租房订单,2-续租订单,3-退租订单,4-转租订单,5-服务订单)" json:"order_type"`
	TenantID         string         `gorm:"type:varchar(64);not null;index;comment:租客ID" json:"tenant_id"`
	LandlordID       string         `gorm:"type:varchar(64);not null;index;comment:房东ID" json:"landlord_id"`
	PropertyID       string         `gorm:"type:varchar(64);not null;index;comment:物业ID" json:"property_id"`
	AgentID          string         `gorm:"type:varchar(64);index;comment:代理商ID" json:"agent_id"`
	OrderStatus      int8           `gorm:"type:tinyint;default:0;index;comment:订单状态(0-待确认,1-已确认,2-进行中,3-已完成,4-已取消,5-已退款)" json:"order_status"`
	PaymentStatus    int8           `gorm:"type:tinyint;default:0;index;comment:支付状态(0-待支付,1-已支付,2-部分支付,3-已退款,4-支付失败)" json:"payment_status"`
	TotalAmount      float64        `gorm:"type:decimal(12,2);not null;default:0;comment:订单总金额" json:"total_amount"`
	PaidAmount       float64        `gorm:"type:decimal(12,2);default:0;comment:已支付金额" json:"paid_amount"`
	RefundAmount     float64        `gorm:"type:decimal(12,2);default:0;comment:已退款金额" json:"refund_amount"`
	LeaseStartDate   time.Time      `gorm:"type:date;not null;index;comment:租赁开始日期" json:"lease_start_date"`
	LeaseEndDate     time.Time      `gorm:"type:date;not null;index;comment:租赁结束日期" json:"lease_end_date"`
	ActualStartDate  *time.Time     `gorm:"type:date;comment:实际开始日期" json:"actual_start_date"`
	ActualEndDate    *time.Time     `gorm:"type:date;comment:实际结束日期" json:"actual_end_date"`
	ContractStatus   int8           `gorm:"type:tinyint;default:0;comment:合同状态(0-未签署,1-已签署,2-已作废)" json:"contract_status"`
	ContractURL      string         `gorm:"type:varchar(500);comment:合同URL" json:"contract_url"`
	ContractSignedAt *time.Time     `gorm:"type:timestamp;comment:合同签署时间" json:"contract_signed_at"`
	CancelReason     string         `gorm:"type:varchar(500);comment:取消原因" json:"cancel_reason"`
	CancelTime       *time.Time     `gorm:"type:timestamp;comment:取消时间" json:"cancel_time"`
	Remark           string         `gorm:"type:text;comment:备注" json:"remark"`
	Items            []*OrderItem   `gorm:"foreignKey:OrderID;comment:订单明细" json:"items"`
	CreatedAt        time.Time      `gorm:"autoCreateTime;index;comment:创建时间" json:"created_at"`
	UpdatedAt        time.Time      `gorm:"autoUpdateTime;comment:更新时间" json:"updated_at"`
	DeletedAt        gorm.DeletedAt `gorm:"index;comment:软删除时间" json:"deleted_at,omitempty"`
}
